package com.example.bigevent.mapper;

import com.example.bigevent.pojo.Event;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EventMapper {
    @Insert("INSERT INTO event(title, content, status, user_id, create_time, update_time) " +
            "VALUES(#{title}, #{content}, #{status}, #{userId}, now(), now())")
    void add(Event event);

    @Select("SELECT * FROM event WHERE user_id = #{userId}")
    List<Event> listByUserId(Integer userId);

    @Select("SELECT * FROM event WHERE id = #{id} AND user_id = #{userId}")
    Event findByIdAndUserId(@Param("id") Integer id, @Param("userId") Integer userId);

    @Update("UPDATE event SET title=#{title}, content=#{content}, status=#{status}, update_time=now() " +
            "WHERE id=#{id} AND user_id=#{userId}")
    void update(Event event);

    @Delete("DELETE FROM event WHERE id = #{id} AND user_id = #{userId}")
    void delete(@Param("id") Integer id, @Param("userId") Integer userId);
}